<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
	<base href="<%=basePath%>">
	<meta charset="utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<!-- basic styles -->
	<link rel="stylesheet" href="assets/css/bootstrap.min.css" />
	<link rel="stylesheet" href="assets/css/bootstrap-responsive.min.css" />
	<link rel="stylesheet" href="assets/css/font-awesome.min.css" />
	<!-- 日期 -->
	<link rel="stylesheet" href="assets/css/bootstrap-datepicker.css" />
	<!-- 下拉框 -->
	<link rel="stylesheet" href="assets/css/chosen.css" />
</head>
<body>
	<form id="addForm" action="admin/admin_save.do" method="post">
		<div class="alert alert-info" style="margin-top:2px;margin-bottom:5px;height:40px;padding-top:10px;padding-bottom:10px;">
			<i class="icon-hand-right"></i>注意：标*的字段为必填项！
		</div>
		<table style="width:100%;border-collapse:separate;border-spacing:5px;">
			<tr>
				<td>管理员账号</td>
				<td><input type="text" name="account"  id="account" maxlength="32" onblur="accountOnblur();" class="col-xs-10 col-sm-5"/>&nbsp;<span style="color: red">*</span></td>
			</tr>
			<tr>
				<td>管理员密码</td>
				<td><input type="password" name="pwd"  id="pwd" maxlength="32"  placeholder="默认111111" class="col-xs-10 col-sm-5"/>&nbsp;<span style="color: red">*</span></td>
			</tr>
			<tr>
				<td>管理员邮箱</td>
				<td><input type="text" name="email"  id="email" maxlength="32"  onblur="emailOnblur();" class="col-xs-10 col-sm-5"/>&nbsp;<span style="color: red">*</span></td>
			</tr>
			<tr>
				<td>管理员手机号</td>
				<td><input type="text" name="phone"  id="phone" maxlength="32" onblur="phoneOnblur();" class="col-xs-10 col-sm-5"/>&nbsp;<span style="color: red">*</span></td>
			</tr>
			<tr>
				<td>管理员属于供应商</td>
				<td>	
				<select name="agentId" class="chosen-select col-xs-10 col-sm-5" >
						<option value="0" >请选择供应商</option>
						<c:forEach items="${agentList}" var="agent">
							<option value="${agent.id }" >${agent.companyName }</option>
						</c:forEach>
					</select>
				</td>
			</tr>
			<tr>
				<td style="float:center;text-align:center;height:60px;" colspan="2">
					<button type="button" onclick="saveBattery();" class="btn btn-info btn-sm "><i class="icon-edit bigger-120">&nbsp;&nbsp;</i>提交</button>
					<button type="button" onclick="top.Dialog.close();" class="btn btn-info btn-sm "><i class="icon-lightbulb bigger-120">&nbsp;&nbsp;</i>取消</button>
				</td>
			</tr>
		</table>
	</form>
<script type="text/javascript" src="assets/js/jquery-1.10.2.min.js"></script>
	<!-- 引入 -->
	<script type="text/javascript" src="assets/js/bootstrap.min.js"></script>
	<!-- 下拉框 -->
	<script type="text/javascript" src="assets/js/chosen.jquery.min.js"></script>
	<!--提示框-->
	<script type="text/javascript" src="assets/js/jquery.tips.js"></script>
	<script type="text/javascript">
	
		$(function() {
			$("table tr").find("td:eq(0)").width(120);
		});
		function accountOnblur(){
		 $.ajax({
				type: "POST",
				url: "admin/admin_check.do",
				data: { account : $("input[name='account']").val()},
				async: true,
				dataType: "text",
				success: function(data) {
					if(data==1){
						showTips($("input[name='account']"),'账号已存在');
						return false; 
					}
				}
			});
		 }
		 function phoneOnblur(){
			 	var inp = document.getElementById("phone");
				var reg = /^(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/;
				var result = reg.test(inp.value);
				if (!result) {
					$("#phone").tips({
						side : 1,
						msg : '手机号格式不对，请重新输入!',
						bg : '#0099FF',
						time : 3
					});
					return false;
				}
		}
		 function emailOnblur(){
			var inp = document.getElementById("email");
			var reg = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
			var result = reg.test(inp.value);
			if (!result) {
				$("#email").tips({
					side : 1,
					msg : '邮箱格式不对，请重新输入!',
					bg : '#0099FF',
					time : 3
				});
				return false;
			}
		}
		function saveBattery() {
			if ($("input[name='account']").val() == "") {
				showTips($("input[name='account']"), '请填写管理员账号！');
				return false;
			}
			if ($("input[name='email']").val() == "") {
				showTips($("input[name='email']"), '请填写管理员邮箱！');

				return false;
			}
			if ($("input[name='phone']").val() == "") {
				showTips($("input[name='phone']"), '请填写管理员手机号！');
				return false;
			}
				var phone = document.getElementById("phone");
				var reg1 = /^(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/;
				var result1 = reg1.test(phone.value);
				if (!result1) {
					$("#companyPhone").tips({
						side : 1,
						msg : '手机号格式不对，请重新输入!',
						bg : '#0099FF',
						time : 3
					});
					return false;
				}
				var email = document.getElementById("email");
				var reg2 = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
				var result2 = reg2.test(email.value);
				if (!result2) {
					$("#email").tips({
						side : 1,
						msg : '邮箱格式不对，请重新输入!',
						bg : '#0099FF',
						time : 3
					});
					return false;
				}
				 $.ajax({
						type: "POST",
						url: "admin/admin_check.do",
						data: { account : $("input[name='account']").val()},
						async: true,
						dataType: "text",
						success: function(data) {
							if(data==1){
								showTips($("input[name='account']"),'账号已存在');
								return false; 
							}else
								$("#addForm").submit();
						}
					});
		};
		function showTips(obj, tips) {
			obj.tips({
				side : 3,
				msg : tips,
				bg : '#e69138',
				time : 2
			});
		}
	</script>
</body>
</html>